define(["constant", "handlebars", "site", "static/js/jquery-plugin/jpager.js"], function (Constant, Handlebars, site) {
    var Public = {
        url: {
            selectPageLogList: "manager/selectPageLogList.do",
            selectApplyTermList: "manager/selectApplyTermList.do",
            selectProductList:"manager/selectProductList.do",
            departmentCascade:'manager/departmentCascade.do'
        },
        recordPageNum: 1,
        queryRecord: function (frontData) {
            var _this = this;
            site.send({
                url: this.url.selectPageLogList,
                data: frontData,
                callback: function (data) {
                    data = JSON.parse(data);
                    if (data.type == 1) {
                        var source = $("#record_list_tpl").html();
                        var template = Handlebars.compile(source);
                        var list = data.content;
                        var html = template(list);
                        $('#record_list').html(html);
                        //分页
                        $('.record-page-container').createPager({
                            current: frontData.pageNum,
                            total: data.content.total,
                            pageSize: data.content.pageSize,
                            needInput: false,
                            backFn: function (current) {
                                frontData.pageNum = current;
                                _this.queryRecord(frontData);
                            }
                        })
                    }
                }
            })
        },
        record: function (Table) {
            var _this = this;
            //操作记录
            $(".operations_record").on('click', function () {
                var id = $(this).attr('id')
                var frontData = {
                    Table: Table,
                    tableId: id,
                    pageNum: _this.recordPageNum
                }
                $('#record_pop').toggle();
                _this.queryRecord(frontData);
            })
        },
        //渲染分期
        initApplyTerm: function () {
            site.send({
                url: this.url.selectApplyTermList,
                callback: function (data) {
                    data = JSON.parse(data);
                    if (data.type == 1) {
                        var source = $("#at_id_tpl").html();
                        var template = Handlebars.compile(source);
                        var html = template(data.content);
                        $('#at_id').html(html);
                    }
                }
            })
        },
        //渲染产品搜索
        initProductSearch:function(){
            site.send({
                url: this.url.selectProductList,
                callback: function (data) {
                    data = JSON.parse(data);
                    if (data.type == 1) {
                        var source = $("#product_choose_list_tpl").html();
                        var template = Handlebars.compile(source);
                        var html = template(data);
                        $('#product_choose_list').append(html);
                    }
                }
            })
        },
        initCompany:function(){
            site.send({
                url: this.url.departmentCascade,//分公司id
                //async:false,
                data: {
                    parentId: 1
                },
                callback: function (data) {
                    var list = JSON.parse(data);
                    var template = Handlebars.compile($("#department_content_tpl").html());
                    var html = template(list);
                    $("#d2Id").html(html);
                }
            })
        }
    }
    return Public;
})